home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / as / dist / ns32k.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-14  |  48.7 KB  |  1,748 lines

  1. /* ns32k.c  -- Assemble on the National Semiconductor 32k series
  2.    Copyright (C) 1987 Free Software Foundation, Inc.
  3.  
  4. This file is part of GAS, the GNU Assembler.
  5.  
  6. GAS is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GAS is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GAS; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. /*#define SHOW_NUM 1*/ /* uncomment for debugging */
  21.  
  22. #include <stdio.h>
  23. #include <ctype.h>
  24. #ifdef USG
  25. #include <string.h>
  26. #else
  27. #include <strings.h>
  28. #endif
  29. #include "ns32k-opcode.h"
  30. #include "as.h"
  31. #include "obstack.h"
  32. #include "frags.h"
  33. #include "struc-symbol.h"
  34. #include "flonum.h"
  35. #include "expr.h"
  36. #include "md.h"
  37. #include "hash.h"
  38. #include "write.h"
  39. #include "symbols.h"
  40.  
  41. /* Macros */
  42. #define IIF_ENTRIES 13                /* number of entries in iif */ 
  43. #define PRIVATE_SIZE 256            /* size of my garbage memory */
  44. #define MAX_ARGS 4
  45. #define DEFAULT    -1        /* addr_mode returns this value when plain constant or label is encountered */
  46.  
  47. #define IIF(ptr,a1,c1,e1,g1,i1,k1,m1,o1,q1,s1,u1) \
  48.   iif.iifP[ptr].type= a1; \
  49.   iif.iifP[ptr].size= c1; \
  50.   iif.iifP[ptr].object= e1; \
  51.   iif.iifP[ptr].object_adjust= g1; \
  52.   iif.iifP[ptr].pcrel= i1; \
  53.   iif.iifP[ptr].pcrel_adjust= k1; \
  54.   iif.iifP[ptr].im_disp= m1; \
  55.   iif.iifP[ptr].relax_substate= o1; \
  56.   iif.iifP[ptr].bit_fixP= q1; \
  57.   iif.iifP[ptr].addr_mode= s1; \
  58.   iif.iifP[ptr].bsr= u1;
  59.  
  60. char comment_chars[] = "|";
  61. char line_comment_chars[] = "#";
  62.  
  63. struct addr_mode {
  64.   char mode;            /* addressing mode of operand (0-31) */
  65.   char scaled_mode;        /* mode combined with scaled mode */
  66.   char scaled_reg;        /* register used in scaled+1 (1-8) */
  67.   char float_flag;        /* set if R0..R7 was F0..F7 ie a floating-point-register */
  68.   char am_size;            /* estimated max size of general addr-mode parts*/
  69.   char im_disp;            /* if im_disp==1 we have a displacement */
  70.   char pcrel;            /* 1 if pcrel, this is really redundant info */
  71.   char disp_suffix[2];        /* length of displacement(s), 0=undefined */
  72.   char *disp[2];        /* pointer(s) at displacement(s)
  73.                               or immediates(s)     (ascii) */
  74.   char index_byte;        /* index byte */
  75. };
  76. typedef struct addr_mode addr_modeS;
  77.  
  78.  
  79. char *freeptr,*freeptr_static; /* points at some number of free bytes */
  80. struct hash_control *inst_hash_handle;
  81.  
  82. struct ns32k_opcode *desc; /* pointer at description of instruction */
  83. addr_modeS addr_modeP;
  84. char EXP_CHARS[] = "eE";
  85. char FLT_CHARS[] = "fd"; /* we don't want to support lowercase, do we */
  86. long omagic = OMAGIC;
  87. void md_number_to_disp();
  88. void md_number_to_imm();
  89. segT evaluate_expr();
  90. void fix_new_ns32k();
  91.  
  92. /* UPPERCASE denotes live names 
  93.  * when an instruction is built, IIF is used as an intermidiate form to store
  94.  * the actual parts of the instruction. A ns32k machine instruction can
  95.  * be divided into a couple of sub PARTs. When an instruction is assembled
  96.  * the appropriate PART get an assignment. When an IIF has been completed it's
  97.  * converted to a FRAGment as specified in AS.H */
  98.  
  99. /* internal structs */
  100. struct option {
  101.   char *pattern;
  102.   unsigned long or;
  103.   unsigned long and;
  104. };
  105.  
  106. typedef struct {
  107.   int            type;        /* how to interpret object */
  108.   int            size;        /* Estimated max size of object */
  109.   unsigned long        object;        /* binary data */
  110.   int            object_adjust;    /* number added to object */
  111.   int            pcrel;        /* True if object is pcrel */
  112.   int            pcrel_adjust;    /* It's value reflects the length in bytes from the instruction start to the displacement */
  113.   int            im_disp;    /* True if the object is a displacement */
  114.   relax_substateT    relax_substate; /* Initial relaxsubstate */
  115.   bit_fixS        *bit_fixP;    /* Pointer at bit_fix struct */ 
  116.   int            addr_mode;    /* What addrmode do we associate with this iif-entry */
  117.   char            bsr;        /* Sequent hack */
  118. }iif_entryT;                /* Internal Instruction Format */
  119. struct int_ins_form {
  120.   int        instr_size;        /* Max size of instruction in bytes. */
  121.   iif_entryT    iifP[IIF_ENTRIES+1];
  122. };
  123. struct int_ins_form iif;
  124. expressionS exprP;
  125. char *input_line_pointer;
  126. /* description of the PARTs in IIF 
  127.  *object[n]:
  128.  * 0    total length in bytes of entries in iif
  129.  * 1    opcode
  130.  * 2    index_byte_a
  131.  * 3    index_byte_b
  132.  * 4    disp_a_1
  133.  * 5    disp_a_2
  134.  * 6    disp_b_1
  135.  * 7    disp_b_2
  136.  * 8    imm_a
  137.  * 9    imm_b
  138.  * 10    implied1
  139.  * 11    implied2
  140.  * 
  141.  * For every entry there is a datalength in bytes. This is stored in size[n].
  142.  *     0,    the objectlength is not explicitly given by the instruction
  143.  *        and the operand is undefined. This is a case for relaxation.
  144.  *        Reserve 4 bytes for the final object.
  145.  *
  146.  *     1,    the entry contains one byte
  147.  *     2,    the entry contains two bytes
  148.  *     3,    the entry contains three bytes
  149.  *     4,    the entry contains four bytes
  150.  *    etc
  151.  *
  152.  * Furthermore, every entry has a data type identifier in type[n].
  153.  *
  154.  *      0,    the entry is void, ignore it.
  155.  *      1,    the entry is a binary number.
  156.  *     2,    the entry is a pointer at an expression.
  157.  *        Where expression may be as simple as a single '1',
  158.  *        and as complicated as  foo-bar+12,
  159.  *         foo and bar may be undefined but suffixed by :{b|w|d} to
  160.  *        control the length of the object.
  161.  *
  162.  *     3,    the entry is a pointer at a bignum struct
  163.  *
  164.  *
  165.  * The low-order-byte coresponds to low physical memory.
  166.  * Obviously a FRAGment must be created for each valid disp in PART whose
  167.  * datalength is undefined (to bad) .
  168.  * The case where just the expression is undefined is less severe and is
  169.  * handled by fix. Here the number of bytes in the objectfile is known.
  170.  * With this representation we simplify the assembly and separates the
  171.  * machine dependent/independent parts in a more clean way (said OE)
  172.  */
  173.  
  174. struct option opt1[]= /* restore, exit */
  175. {
  176.   { "r0",    0x80,    0xff    },
  177.   { "r1",    0x40,    0xff    },
  178.   { "r2",    0x20,    0xff    },
  179.   { "r3",    0x10,    0xff    },
  180.   { "r4",    0x08,    0xff    },
  181.   { "r5",    0x04,    0xff    },
  182.   { "r6",    0x02,    0xff    },
  183.   { "r7",    0x01,    0xff    },
  184.   {  0 ,    0x00,    0xff    }
  185. };
  186. struct option opt2[]= /* save, enter */
  187. {
  188.   { "r0",    0x01,    0xff    },
  189.   { "r1",    0x02,    0xff    },
  190.   { "r2",    0x04,    0xff    },
  191.   { "r3",    0x08,    0xff    },
  192.   { "r4",    0x10,    0xff    },
  193.   { "r5",    0x20,    0xff    },
  194.   { "r6",    0x40,    0xff    },
  195.   { "r7",    0x80,    0xff    },
  196.   {  0 ,    0x00,    0xff    }
  197. };
  198. struct option opt3[]= /* setcfg */
  199. {
  200.   { "c",    0x8,    0xff    },
  201.   { "m",    0x4,    0xff    },
  202.   { "f",    0x2,    0xff    },
  203.   { "i",    0x1,    0xff    },
  204.   {  0 ,    0x0,    0xff    }
  205. };
  206. struct option opt4[]= /* cinv */
  207. {
  208.   { "a",    0x4,    0xff    },
  209.   { "i",    0x2,    0xff    },
  210.   { "d",    0x1,    0xff    },
  211.   {  0 ,    0x0,    0xff    }
  212. };
  213. struct option opt5[]= /* string inst */
  214. {
  215.   { "b",    0x2,    0xff    },
  216.   { "u",    0xc,    0xff    },
  217.   { "w",    0x4,    0xff    },
  218.   {  0 ,    0x0,    0xff    }
  219. };
  220. struct option opt6[]= /* plain reg ext,cvtp etc */
  221. {
  222.   { "r0",    0x00,    0xff    },
  223.   { "r1",    0x01,    0xff    },
  224.   { "r2",    0x02,    0xff    },
  225.   { "r3",    0x03,    0xff    },
  226.   { "r4",    0x04,    0xff    },
  227.   { "r5",    0x05,    0xff    },
  228.   { "r6",    0x06,    0xff    },
  229.   { "r7",    0x07,    0xff    },
  230.   {  0 ,    0x00,    0xff    }
  231. };
  232.  
  233. #if !defined(NS32032) && !defined(NS32532)
  234. #define NS32032
  235. #endif
  236.  
  237. struct option cpureg_532[]= /* lpr spr */
  238. {
  239.   { "us",    0x0,    0xff    },
  240.   { "dcr",    0x1,    0xff    },
  241.   { "bpc",    0x2,    0xff    },
  242.   { "dsr",    0x3,    0xff    },
  243.   { "car",    0x4,    0xff    },
  244.   { "fp",    0x8,    0xff    },
  245.   { "sp",    0x9,    0xff    },
  246.   { "sb",    0xa,    0xff    },
  247.   { "usp",    0xb,    0xff    },
  248.   { "cfg",    0xc,    0xff    },
  249.   { "psr",    0xd,    0xff    },
  250.   { "intbase",    0xe,    0xff    },
  251.   { "mod",    0xf,    0xff    },
  252.   {  0 ,    0x00,    0xff    }
  253. };
  254. struct option mmureg_532[]= /* lmr smr */
  255. {
  256.   { "mcr",    0x9,    0xff    },
  257.   { "msr",    0xa,    0xff    },
  258.   { "tear",    0xb,    0xff    },
  259.   { "ptb0",    0xc,    0xff    },
  260.   { "ptb1",    0xd,    0xff    },
  261.   { "ivar0",    0xe,    0xff    },
  262.   { "ivar1",    0xf,    0xff    },
  263.   {  0 ,    0x0,    0xff    }
  264. };
  265.  
  266. struct option cpureg_032[]= /* lpr spr */
  267. {
  268.   { "upsr",    0x0,    0xff    },
  269.   { "fp",    0x8,    0xff    },
  270.   { "sp",    0x9,    0xff    },
  271.   { "sb",    0xa,    0xff    },
  272.   { "psr",    0xb,    0xff    },
  273.   { "intbase",    0xe,    0xff    },
  274.   { "mod",    0xf,    0xff    },
  275.   {  0 ,    0x0,    0xff    }
  276. };
  277. struct option mmureg_032[]= /* lmr smr */
  278. {
  279.   { "bpr0",    0x0,    0xff    },
  280.   { "bpr1",    0x1,    0xff    },
  281.   { "pf0",    0x4,    0xff    },
  282.   { "pf1",    0x5,    0xff    },
  283.   { "sc",    0x8,    0xff    },
  284.   { "msr",    0xa,    0xff    },
  285.   { "bcnt",    0xb,    0xff    },
  286.   { "ptb0",    0xc,    0xff    },
  287.   { "ptb1",    0xd,    0xff    },
  288.   { "eia",    0xf,    0xff    },
  289.   {  0 ,    0x0,    0xff    }
  290. };
  291.  
  292. #if defined(NS32532)
  293. struct option *cpureg = cpureg_532;
  294. struct option *mmureg = mmureg_532;
  295. #else
  296. struct option *cpureg = cpureg_032;
  297. struct option *mmureg = mmureg_032;
  298. #endif
  299.  
  300.  
  301. pseudo_typeS md_pseudo_table[]={ /* so far empty */
  302.   { 0,    0,    0    }
  303. };
  304.  
  305. #define IND(x,y)    (((x)<<2)+(y))
  306.  
  307. /* those are index's to relax groups in md_relax_table 
  308.    ie it must be multiplied by 4 to point at a group start. Viz IND(x,y)
  309.    Se function relax_segment in write.c for more info */
  310.  
  311. #define BRANCH        1
  312. #define PCREL        2 
  313.  
  314. /* those are index's to entries in a relax group */
  315.  
  316. #define BYTE        0
  317. #define WORD        1
  318. #define DOUBLE        2
  319. #define UNDEF           3
  320. /* Those limits are calculated from the displacement start in memory.
  321.    The ns32k uses the begining of the instruction as displacement base.
  322.    This type of displacements could be handled here by moving the limit window
  323.    up or down. I choose to use an internal displacement base-adjust as there
  324.    are other routines that must consider this. Also, as we have two various
  325.    offset-adjusts in the ns32k (acb versus br/brs/jsr/bcond), two set of limits
  326.    would have had to be used.
  327.    Now we dont have to think about that. */
  328.  
  329.  
  330. relax_typeS md_relax_table[]={
  331.   { 1,        1,        0,    0            },
  332.   { 1,        1,        0,    0            },
  333.   { 1,        1,        0,    0            },
  334.   { 1,        1,        0,    0            },
  335.  
  336.   { (63-22),    (-(64-22)),    1,    IND(BRANCH,WORD)    },
  337.   { (8192-22),    (-(8192-22)),    2,    IND(BRANCH,DOUBLE)    },
  338.   { 0,        0,        4,    0            },
  339.   { 1,        1,        0,    0            }
  340. };
  341.  
  342. /* Array used to test if mode contains displacements.
  343.    Value is true if mode contains displacement. */
  344.  
  345. char disp_test[]={ 0,0,0,0,0,0,0,0,
  346.            1,1,1,1,1,1,1,1,
  347.            1,1,1,0,0,1,1,0,
  348.            1,1,1,1,1,1,1,1 };
  349.  
  350. /* Array used to calculate max size of displacements */
  351.  
  352. char disp_size[]={ 4,1,2,0,4 };
  353.  
  354. /* Parses a general operand into an addressingmode struct 
  355.  
  356.    in:  pointer at operand in ascii form
  357.         pointer at addr_mode struct for result
  358.     the level of recursion. (always 0 or 1)
  359.  
  360.    out: data in addr_mode struct
  361.  */
  362. int addr_mode(operand,addr_modeP,recursive_level)
  363.      char *operand;
  364.      register addr_modeS *addr_modeP;
  365. int recursive_level;
  366. {
  367.   register char *str;
  368.   register char c;
  369.   register int i;
  370.   register int strl;
  371.   register int mode;
  372.   int j;
  373.   mode = DEFAULT;                 /* default */
  374.   addr_modeP->scaled_mode=0;        /* why not */
  375.   addr_modeP->scaled_reg=0;        /* if 0, not scaled index */
  376.   addr_modeP->float_flag=0;
  377.   addr_modeP->am_size=0;
  378.   addr_modeP->im_disp=0;
  379.   addr_modeP->pcrel=0;            /* not set in this function */
  380.   addr_modeP->disp_suffix[0]=0;
  381.   addr_modeP->disp_suffix[1]=0;
  382.   addr_modeP->disp[0]=NULL;
  383.   addr_modeP->disp[1]=NULL;
  384.   str=operand;
  385.   if (str[0]==0) {return (0);}        /* we don't want this */
  386.   strl=strlen(str);               
  387.   switch (str[0]) {
  388.     /* the following three case statements controls the mode-chars
  389.        this is the place to ed if you want to change them */
  390.   case '@':
  391.     if (str[strl-1]==']') break;
  392.     addr_modeP->mode=21;        /* absolute */
  393.     addr_modeP->disp[0]=str+1;
  394.     return (-1);
  395.   case '#':        
  396.     if (str[strl-1]==']') break;
  397.     addr_modeP->mode=20;        /* immediate */
  398.     addr_modeP->disp[0]=str+1;
  399.     return (-1);
  400.   case '.':
  401.     if (str[strl-1]!=']') {
  402.       switch (str[1]) {
  403.       case'-':case'+':
  404.         if (str[2]!='\000') {
  405.       addr_modeP->mode=27;        /* pc-relativ */
  406.       addr_modeP->disp[0]=str+2;
  407.       return (-1);
  408.     }
  409.       default:
  410.         as_warn("Invalid syntax in PC-relative addressing mode");
  411.         return(0);
  412.       }
  413.     }
  414.     break;
  415.   case'e':
  416.     if (str[strl-1]!=']') {
  417.       if((!strncmp(str,"ext(",4)) && strl>7) {    /* external */
  418.     addr_modeP->disp[0]=str+4;
  419.     i=0;
  420.     j=2;
  421.     do {                 /* disp[0]'s termination point */
  422.       j+=1;
  423.       if (str[j]=='(') i++;
  424.       if (str[j]==')') i--;
  425.     } while (j<strl && i!=0);
  426.     if (i!=0 || !(str[j+1]=='-' || str[j+1]=='+') ) {
  427.       as_warn("Invalid syntax in External addressing mode");
  428.       return(0);
  429.     }
  430.     str[j]='\000';            /* null terminate disp[0] */
  431.     addr_modeP->disp[1]=str+j+2;
  432.     addr_modeP->mode=22;
  433.     return (-1);
  434.       }
  435.     }
  436.   break;
  437.   default:;
  438.   }
  439.   strl=strlen(str);               
  440.   switch(strl) {
  441.   case 2:
  442.     switch (str[0]) {
  443.     case'f':addr_modeP->float_flag=1;
  444.     case'r':
  445.       if (str[1]>='0' && str[1]<'8') {
  446.     addr_modeP->mode=str[1]-'0';
  447.     return (-1);
  448.       }
  449.     }
  450.   case 3:
  451.     if (!strncmp(str,"tos",3)) {
  452.       addr_modeP->mode=23; /* TopOfStack */
  453.       return (-1);
  454.     }
  455.   default:;
  456.   }
  457.   if (strl>4) {
  458.     if (str[strl-1]==')') {
  459.       if (str[strl-2]==')') {
  460.     if (!strncmp(&str[strl-5],"(fp",3)) {
  461.       mode=16; /* Memory Relative */
  462.     }
  463.     if (!strncmp(&str[strl-5],"(sp",3)) {
  464.       mode=17;
  465.     }
  466.     if (!strncmp(&str[strl-5],"(sb",3)) {
  467.       mode=18;
  468.     }
  469.     if (mode!=DEFAULT) {          /* memory relative */
  470.       addr_modeP->mode=mode;
  471.       j=strl-5; /* temp for end of disp[0] */
  472.       i=0;
  473.       do {
  474.         strl-=1;
  475.         if (str[strl]==')') i++;
  476.         if (str[strl]=='(') i--;
  477.       } while (strl>-1 && i!=0);
  478.       if (i!=0) {
  479.         as_warn("Invalid syntax in Memory Relative addressing mode");
  480.         return(0);
  481.       }
  482.       addr_modeP->disp[1]=str;
  483.       addr_modeP->disp[0]=str+strl+1;
  484.       str[j]='\000'; /* null terminate disp[0] */
  485.       str[strl]='\000'; /* null terminate disp[1] */
  486.       return (-1);
  487.     }
  488.       }
  489.       switch (str[strl-3]) {
  490.       case'r':case'R':
  491.         if (str[strl-2]>='0' && str[strl-2]<'8' && str[strl-4]=='(') {
  492.       addr_modeP->mode=str[strl-2]-'0'+8;
  493.       addr_modeP->disp[0]=str;
  494.       str[strl-4]=0;
  495.       return (-1); /* reg rel */
  496.     }
  497.       default:
  498.         if (!strncmp(&str[strl-4],"(fp",3)) {
  499.       mode=24;
  500.     }
  501.         if (!strncmp(&str[strl-4],"(sp",3)) {
  502.       mode=25;
  503.     }
  504.         if (!strncmp(&str[strl-4],"(sb",3)) {
  505.       mode=26;
  506.     }
  507.     if (!strncmp(&str[strl-4],"(pc",3)) {
  508.       mode=27;
  509.     }
  510.         if (mode!=DEFAULT) {
  511.       addr_modeP->mode=mode;
  512.       addr_modeP->disp[0]=str;
  513.       str[strl-4]='\0';
  514.       return (-1); /* memory space */
  515.     }
  516.       }
  517.     }
  518.      /* no trailing ')' do we have a ']' ? */
  519.     if (str[strl-1]==']') {
  520.       switch (str[strl-2]) {
  521.       case'b':mode=28;break;
  522.       case'w':mode=29;break;
  523.       case'd':mode=30;break;
  524.       case'q':mode=31;break;
  525.       default:;
  526.         as_warn("Invalid scaled-indexed mode, use (b,w,d,q)");
  527.         if (str[strl-3]!=':' || str[strl-6]!='[' ||
  528.         str[strl-5]=='r' || str[strl-4]<'0' || str[strl-4]>'7') {
  529.       as_warn("Syntax in scaled-indexed mode, use [Rn:m] where n=[0..7] m={b,w,d,q}");
  530.     }
  531.       }  /* scaled index */
  532.       {
  533.     if (recursive_level>0) {
  534.       as_warn("Scaled-indexed addressing mode combined with scaled-index");
  535.       return(0);
  536.     }
  537.     addr_modeP->am_size+=1;        /* scaled index byte */
  538.     j=str[strl-4]-'0';        /* store temporary */
  539.     str[strl-6]='\000';        /* nullterminate for recursive call */
  540.     i=addr_mode(str,addr_modeP,1);
  541.     if (!i || addr_modeP->mode==20) {
  542.       as_warn("Invalid or illegal addressing mode combined with scaled-index");
  543.       return(0);
  544.     }
  545.     addr_modeP->scaled_mode=addr_modeP->mode; /* store the inferior mode */
  546.     addr_modeP->mode=mode;
  547.     addr_modeP->scaled_reg=j+1;
  548.     return (-1);
  549.       }
  550.     }
  551.   }
  552.   addr_modeP->mode = DEFAULT;    /* default to whatever */
  553.   addr_modeP->disp[0]=str;
  554.   return (-1);
  555. }
  556.  
  557. /* ptr points at string
  558.    addr_modeP points at struct with result
  559.    This routine calls addr_mode to determine the general addr.mode of
  560.    the operand. When this is ready it parses the displacements for size
  561.    specifying suffixes and determines size of immediate mode via ns32k-opcode.
  562.    Also builds index bytes if needed.
  563.  */
  564. int get_addr_mode(ptr,addr_modeP)
  565.      char *ptr;
  566.      addr_modeS *addr_modeP;
  567. {
  568.   int tmp;
  569.   addr_mode(ptr,addr_modeP,0);
  570.   if (addr_modeP->mode == DEFAULT || addr_modeP->scaled_mode == -1) {
  571.                    /* resolve ambigious operands, this shouldn't
  572.                   be necessary if one uses standard NSC operand
  573.                   syntax. But the sequent compiler doesn't!!!
  574.                   This finds a proper addressinging mode if it
  575.                   is implicitly stated. See ns32k-opcode.h */
  576.     (void)evaluate_expr(&exprP,ptr); /* this call takes time Sigh! */
  577.     if (addr_modeP->mode == DEFAULT) {
  578.       if (exprP.X_add_symbol || exprP.X_subtract_symbol) {
  579.     addr_modeP->mode=desc->default_model; /* we have a label */
  580.       } else {
  581.     addr_modeP->mode=desc->default_modec; /* we have a constant */
  582.       }
  583.     } else {
  584.       if (exprP.X_add_symbol || exprP.X_subtract_symbol) {
  585.     addr_modeP->scaled_mode=desc->default_model;
  586.       } else {
  587.     addr_modeP->scaled_mode=desc->default_modec;
  588.       }
  589.     }
  590.     /* must put this mess down in addr_mode to handle the scaled case better */
  591.   }
  592.   /* It appears as the sequent compiler wants an absolute when we have a
  593.      label without @. Constants becomes immediates besides the addr case.
  594.      Think it does so with local labels too, not optimum, pcrel is better.
  595.      When I have time I will make gas check this and select pcrel when possible
  596.      Actually that is trivial.
  597.      */
  598.   if (tmp=addr_modeP->scaled_reg) { /* build indexbyte */
  599.     tmp--; /* remember regnumber comes incremented for flagpurpose */
  600.     tmp|=addr_modeP->scaled_mode<<3;
  601.     addr_modeP->index_byte=(char)tmp;
  602.     addr_modeP->am_size+=1;
  603.   }
  604.   if (disp_test[addr_modeP->mode]) { /* there was a displacement, probe for length specifying suffix*/
  605.     {
  606.       register char c;
  607.       register char suffix;
  608.       register char suffix_sub;
  609.       register int i;
  610.       register char *toP;
  611.       register char *fromP;
  612.  
  613.       addr_modeP->pcrel=0;
  614.       if (disp_test[addr_modeP->mode]) { /* there is a displacement */
  615.     if (addr_modeP->mode==27 || addr_modeP->scaled_mode==27) { /* do we have pcrel. mode */
  616.       addr_modeP->pcrel=1;
  617.     }
  618.     addr_modeP->im_disp=1;
  619.     for(i=0;i<2;i++) {
  620.       suffix_sub=suffix=0;
  621.       if (toP=addr_modeP->disp[i]) { /* suffix of expression, the largest size rules */
  622.         fromP=toP;
  623.         while (c = *fromP++) {
  624.           *toP++=c;
  625.           if (c==':') {
  626.         switch (*fromP) {
  627.         case '\0':
  628.           as_warn("Premature end of suffix--Defaulting to d");
  629.           suffix=4;
  630.           continue;
  631.         case 'b':suffix_sub=1;break;
  632.         case 'w':suffix_sub=2;break;
  633.         case 'd':suffix_sub=4;break;
  634.         default:
  635.           as_warn("Bad suffix after ':' use {b|w|d} Defaulting to d");
  636.           suffix=4;
  637.         }
  638.         fromP++;
  639.         toP--; /* So we write over the ':' */
  640.         if (suffix<suffix_sub) suffix=suffix_sub;
  641.           }
  642.         }
  643.         *toP='\0'; /* terminate properly */
  644.         addr_modeP->disp_suffix[i]=suffix;
  645.         addr_modeP->am_size+=suffix ? suffix : 4;
  646.       }
  647.     }
  648.       }
  649.     }
  650.   } else {
  651.     if (addr_modeP->mode==20) { /* look in ns32k_opcode for size */
  652.       addr_modeP->disp_suffix[0]=addr_modeP->am_size=desc->im_size;
  653.       addr_modeP->im_disp=0;
  654.     }
  655.   }
  656.   return addr_modeP->mode;
  657. }
  658.  
  659.  
  660. /* read an optionlist */
  661. void optlist(str,optionP,default_map)
  662.      char *str;             /* the string to extract options from */
  663.      struct option *optionP;     /* how to search the string */
  664.      unsigned long *default_map; /* default pattern and output */
  665. {
  666.   register int i,j,k,strlen1,strlen2;
  667.   register char *patternP,*strP;
  668.   strlen1=strlen(str);
  669.   if (strlen1<1) { 
  670.     as_fatal("Very short instr to option, ie you can't do it on a NULLstr");
  671.   }
  672.   for (i=0;optionP[i].pattern!=0;i++) {
  673.     strlen2=strlen(optionP[i].pattern);
  674.     for (j=0;j<strlen1;j++) {
  675.       patternP=optionP[i].pattern;
  676.       strP = &str[j];
  677.       for (k=0;k<strlen2;k++) {
  678.     if (*(strP++)!=*(patternP++)) break;
  679.       }
  680.       if (k==strlen2) { /* match */
  681.     *default_map|=optionP[i].or;
  682.     *default_map&=optionP[i].and;
  683.       }
  684.     }
  685.   }
  686. }
  687. /* search struct for symbols 
  688.    This function is used to get the short integer form of reg names
  689.    in the instructions lmr, smr, lpr, spr
  690.    return true if str is found in list */
  691.  
  692. int list_search(str,optionP,default_map)
  693.      char *str;             /* the string to match */
  694.      struct option *optionP;     /* list to search */
  695.      unsigned long *default_map; /* default pattern and output */
  696. {
  697.   register int i;
  698.   for (i=0;optionP[i].pattern!=0;i++) {
  699.     if (!strncmp(optionP[i].pattern,str,20)) { /* use strncmp to be safe */
  700.       *default_map|=optionP[i].or;
  701.       *default_map&=optionP[i].and;
  702.       return -1;
  703.     }
  704.   }
  705.   as_warn("No such entry in list. (cpu/mmu register)");
  706.   return 0;
  707. }
  708. segT evaluate_expr(resultP,ptr)
  709. expressionS *resultP;
  710. char *ptr;
  711. {
  712.   register char *tmp_line;
  713.   register segT segment;
  714.   tmp_line=input_line_pointer;
  715.   input_line_pointer=ptr;
  716.   segment=expression(&exprP);
  717.   input_line_pointer=tmp_line;
  718.   return (segment);
  719. }
  720.  
  721. /* Convert operands to iif-format and adds bitfields to the opcode.
  722.    Operands are parsed in such an order that the opcode is updated from
  723.    its most significant bit, that is when the operand need to alter the
  724.    opcode.
  725.    Be carefull not to put to objects in the same iif-slot.
  726.    */
  727.  
  728. encode_operand(argc,argv,operandsP,suffixP,im_size,opcode_bit_ptr)
  729.      int argc;
  730.      char **argv;
  731.      char *operandsP;
  732.      char *suffixP;
  733.      char im_size;
  734.      char opcode_bit_ptr;
  735. {
  736.   register int i,j;
  737.   int pcrel,tmp,b,loop,pcrel_adjust;
  738.   for(loop=0;loop<argc;loop++) {
  739.     i=operandsP[loop<<1]-'1'; /* what operand are we supposed to work on */
  740.     if (i>3) as_fatal("Internal error check ns32k-opcode.h");
  741.     pcrel=0;
  742.     pcrel_adjust=0;
  743.     tmp=0;
  744.     switch (operandsP[(loop<<1)+1]) {
  745.     case 'f':  /* operand of sfsr turns out to be a nasty specialcase */
  746.       opcode_bit_ptr-=5;
  747.     case 'F':        /* 32 bit float    general form */
  748.     case 'L':        /* 64 bit float    */
  749.     case 'Q':        /* quad-word    */
  750.     case 'B':        /* byte     */
  751.     case 'W':        /* word     */
  752.     case 'D':        /* double-word    */
  753.     case 'A':        /* double-word    gen-address-form ie no regs allowed */
  754.       get_addr_mode(argv[i],&addr_modeP);
  755.       iif.instr_size+=addr_modeP.am_size;
  756.       if (opcode_bit_ptr==desc->opcode_size) b=4; else b=6;
  757.       for (j=b;j<(b+2);j++) { 
  758.     if (addr_modeP.disp[j-b]) { 
  759.       IIF(j,
  760.           2,
  761.           addr_modeP.disp_suffix[j-b],
  762.           (unsigned long)addr_modeP.disp[j-b],
  763.           0,
  764.           addr_modeP.pcrel,
  765.           iif.instr_size-addr_modeP.am_size, /* this aint used (now) */
  766.           addr_modeP.im_disp,
  767.           IND(BRANCH,BYTE),
  768.           NULL,
  769.           addr_modeP.scaled_reg ? addr_modeP.scaled_mode:addr_modeP.mode,
  770.           0);
  771.     }
  772.       }
  773.       opcode_bit_ptr-=5;
  774.       iif.iifP[1].object|=((long)addr_modeP.mode)<<opcode_bit_ptr;
  775.       if (addr_modeP.scaled_reg) { 
  776.     j=b/2;
  777.     IIF(j,1,1, (unsigned long)addr_modeP.index_byte,0,0,0,0,0, NULL,-1,0);
  778.       }
  779.       break;
  780.     case 'b':        /* multiple instruction disp */
  781.       freeptr++;    /* OVE:this is an useful hack */
  782.       tmp=(int)sprintf(freeptr,"((%s-1)*%d)\000",argv[i],desc->im_size);
  783.       argv[i]=freeptr;
  784.       freeptr=(char*)tmp;
  785.       pcrel-=1; /* make pcrel 0 inspite of what case 'p': wants */
  786.       /* fall thru */
  787.     case 'p':        /* displacement - pc relative addressing */
  788.       pcrel+=1;
  789.       /* fall thru */
  790.     case 'd':                    /* displacement */
  791.       iif.instr_size+=suffixP[i] ? suffixP[i] : 4;
  792.       IIF(12, 2, suffixP[i], (unsigned long)argv[i], 0,
  793.       pcrel, pcrel_adjust, 1, IND(BRANCH,BYTE), NULL,-1,0);
  794.       break;
  795.     case 'H': /* sequent-hack: the linker wants a bit set when bsr */
  796.       pcrel=1;
  797.       iif.instr_size+=suffixP[i] ? suffixP[i] : 4;
  798.       IIF(12, 2, suffixP[i], (unsigned long)argv[i], 0,
  799.       pcrel, pcrel_adjust, 1, IND(BRANCH,BYTE), NULL,-1,1);break;
  800.     case 'q':                    /* quick */
  801.       opcode_bit_ptr-=4;
  802.       IIF(11,2,42,(unsigned long)argv[i],0,0,0,0,0,
  803.       bit_fix_new(4,opcode_bit_ptr,-8,7,0,1,0),-1,0);
  804.       break;
  805.     case 'r':                /* register number (3 bits) */
  806.       list_search(argv[i],opt6,&tmp);
  807.       opcode_bit_ptr-=3;
  808.       iif.iifP[1].object|=tmp<<opcode_bit_ptr;
  809.       break;
  810.     case 'O':                /* setcfg instruction optionslist */
  811.       optlist(argv[i],opt3,&tmp);
  812.       opcode_bit_ptr-=4;
  813.       iif.iifP[1].object|=tmp<<15;
  814.       break;
  815.     case 'C':                /* cinv instruction optionslist */
  816.       optlist(argv[i],opt4,&tmp);
  817.       opcode_bit_ptr-=4;
  818.       iif.iifP[1].object|=tmp<<15;/*insert the regtype in opcode */
  819.       break;
  820.     case 'S':                /* stringinstruction optionslist */
  821.       optlist(argv[i],opt5,&tmp);
  822.       opcode_bit_ptr-=4;
  823.       iif.iifP[1].object|=tmp<<15;
  824.       break;
  825.     case 'u':case 'U':                /* registerlist */
  826.       IIF(10,1,1,0,0,0,0,0,0,NULL,-1,0);
  827.       switch (operandsP[(i<<1)+1]) {
  828.       case 'u':                       /* restore, exit */
  829.     optlist(argv[i],opt1,&iif.iifP[10].object);
  830.     break;
  831.       case 'U':                    /* save,enter */
  832.     optlist(argv[i],opt2,&iif.iifP[10].object);
  833.     break;
  834.       }
  835.       iif.instr_size+=1;
  836.       break;
  837.     case 'M':                    /* mmu register */
  838.       list_search(argv[i],mmureg,&tmp);
  839.       opcode_bit_ptr-=4;
  840.       iif.iifP[1].object|=tmp<<opcode_bit_ptr;
  841.       break;
  842.     case 'P':                    /* cpu register  */
  843.       list_search(argv[i],cpureg,&tmp);
  844.       opcode_bit_ptr-=4;
  845.       iif.iifP[1].object|=tmp<<opcode_bit_ptr;
  846.       break;
  847.     case 'g': /* inss exts */
  848.       iif.instr_size+=1; /* 1 byte is allocated after the opcode */
  849.       IIF(10,2,1,
  850.       (unsigned long)argv[i], /* i always 2 here */
  851.       0,0,0,0,0,
  852.       bit_fix_new(3,5,0,7,0,0,0), /* a bit_fix is targeted to the byte */
  853.       -1,0);
  854.     case 'G':
  855.       IIF(11,2,42,
  856.       (unsigned long)argv[i], /* i always 3 here */
  857.       0,0,0,0,0,
  858.       bit_fix_new(5,0,1,32,-1,0,-1),-1,0);
  859.       break;
  860.     case 'i':
  861.       iif.instr_size+=1;
  862.       b=2+i;  /* put the extension byte after opcode */
  863.       IIF(b,2,1,0,0,0,0,0,0,0,-1,0);
  864.     default:
  865.       as_fatal("Bad opcode-table-option, check in file ns32k-opcode.h");
  866.     }
  867.   }
  868. }
  869.  
  870. /* in:  instruction line
  871.    out: internal structure of instruction
  872.         that has been prepared for direct conversion to fragment(s) and
  873.     fixes in a systematical fashion
  874.     Return-value = recursive_level
  875. */
  876. /* build iif of one assembly text line */
  877. int parse(line,recursive_level)
  878.      char *line;
  879.      int recursive_level;
  880. {
  881.   register char            *lineptr,c,suffix_separator;
  882.   register int            i,j;
  883.   register long int        opcode;
  884.   unsigned long             tmp;
  885.   int                arg_count,argc,line_len,arg_type;
  886.   char                sqr,sep;
  887.   char suffix[MAX_ARGS],*argv[MAX_ARGS],*tmp_line;/* no more than 4 operands */
  888.   int opcode_bit_ptr;
  889.   if (recursive_level<=0) { /* called from md_assemble */
  890.     for (lineptr=line;(*lineptr)!='\0' && (*lineptr)!=' ';lineptr++); 
  891.     c = *lineptr;
  892.     *lineptr='\0';
  893.     if (!(desc=(struct ns32k_opcode*)hash_find(inst_hash_handle,line))) {
  894.       as_fatal("No such opcode");
  895.     }
  896.     *lineptr=c;
  897.   } else {
  898.     lineptr=line;
  899.   }
  900.   argc=0;
  901.   if (*desc->operands) {
  902.     if (*lineptr++!='\0') {
  903.       sqr='[';
  904.       sep=',';
  905.       while (*lineptr!='\0') {
  906.     if (desc->operands[argc<<1]) {
  907.       suffix[argc]=0;
  908.       arg_type=desc->operands[(argc<<1)+1];
  909.       switch (arg_type) {
  910.       case 'd': case 'b': case 'p': case 'H':  /* the operand is supposed to be a displacement */
  911.         /* Hackwarning: do not forget to update the 4 cases above when editing ns32k-opcode.h */
  912.         suffix_separator=':';
  913.         break;
  914.       default:
  915.         suffix_separator='\255'; /* if this char occurs we loose */
  916.       }
  917.       suffix[argc]=0; /* 0 when no ':' is encountered */
  918.       argv[argc]=freeptr;
  919.       *freeptr='\0';
  920.       while ((c = *lineptr)!='\0' && c!=sep) {
  921.         if (c==sqr) {
  922.           if (sqr=='[') {
  923.         sqr=']';sep='\0';
  924.           } else {
  925.         sqr='[';sep=',';
  926.           }
  927.         }
  928.         if (c==suffix_separator) { /* ':' - label/suffix separator */
  929.           switch (lineptr[1]) {
  930.           case 'b':suffix[argc]=1;break;
  931.           case 'w':suffix[argc]=2;break;
  932.           case 'd':suffix[argc]=4;break;
  933.           default: as_warn("Bad suffix, defaulting to d");
  934.         suffix[argc]=4;
  935.         if (lineptr[1]=='\0' || lineptr[1]==sep) {
  936.           lineptr+=1;
  937.           continue;
  938.         }
  939.           }
  940.           lineptr+=2;
  941.           continue;
  942.         }
  943.         *freeptr++=c;
  944.         lineptr++;
  945.       }
  946.       *freeptr++='\0';
  947.       argc+=1;
  948.       if (*lineptr=='\0') continue;
  949.       lineptr+=1;
  950.     } else {
  951.       as_fatal("Too many operands passed to instruction");
  952.     }
  953.       }
  954.     }
  955.   }
  956.   if (argc!=strlen(desc->operands)/2) {
  957.     if (strlen(desc->default_args)) { /* we can apply default, dont goof */
  958.       if (parse(desc->default_args,1)!=1) { /* check error in default */
  959.     as_fatal("Wrong numbers of operands in default, check ns32k-opcodes.h");
  960.       }
  961.     } else {
  962.       as_fatal("Wrong number of operands");
  963.     }
  964.  
  965.   }
  966.   for (i=0;i<IIF_ENTRIES;i++) {
  967.     iif.iifP[i].type=0; /* mark all entries as void*/
  968.   }
  969.  
  970.     /* build opcode iif-entry */
  971.   iif.instr_size=desc->opcode_size/8;
  972.   IIF(1,1,iif.instr_size,desc->opcode_seed,0,0,0,0,0,0,-1,0);
  973.  
  974.     /* this call encodes operands to iif format */
  975.   if (argc) {
  976.     encode_operand(argc,
  977.            argv,
  978.            &desc->operands[0],
  979.            &suffix[0],
  980.            desc->im_size,
  981.            desc->opcode_size);
  982.   }
  983.   return recursive_level;
  984. }
  985.  
  986.  
  987.   /* Convert iif to fragments.
  988.      From this point we start to dribble with functions in other files than
  989.      this one.(Except hash.c) So, if it's possible to make an iif for an other
  990.      CPU, you don't need to know what frags, relax, obstacks, etc is in order
  991.      to port this assembler. You only need to know if it's possible to reduce
  992.      your cpu-instruction to iif-format (takes some work) and adopt the other
  993.      md_? parts according to given instructions
  994.      Note that iif was invented for the clean ns32k`s architecure.
  995.      */
  996. convert_iif()
  997. {
  998.   register int            i,j;
  999.   fragS             *inst_frag;
  1000.   char                *inst_offset,*inst_opcode;
  1001.   char                *memP;
  1002.   segT                segment;
  1003.   int                l,k;
  1004.   register int rem_size; /* count the remaining bytes of instruction */
  1005.   register char type;
  1006.   register char size = 0;
  1007.   int    size_so_far=0; /* used to calculate pcrel_adjust */
  1008.  
  1009.     rem_size=iif.instr_size;
  1010.     memP=frag_more(iif.instr_size); /* make sure we have enough bytes for instruction */
  1011.     inst_opcode=memP;
  1012.     inst_offset=(char*)(memP-frag_now->fr_literal);
  1013.     inst_frag=frag_now;
  1014.     for (i=0;i<IIF_ENTRIES;i++) {
  1015.       if (type=iif.iifP[i].type) {            /* the object exist, so handle it */
  1016.     switch (size=iif.iifP[i].size) {
  1017.     case 42: size=0; /* it's a bitfix that operates on an existing object*/
  1018.       if (iif.iifP[i].bit_fixP->fx_bit_base) { /* expand fx_bit_base to point at opcode */
  1019.         iif.iifP[i].bit_fixP->fx_bit_base=(long)inst_opcode;
  1020.       }
  1021.     case 8: /* bignum or doublefloat */
  1022.       bzero (memP,8);
  1023.     case 1:case 2:case 3:case 4:/* the final size in objectmemory is known */
  1024.       j=(unsigned long)iif.iifP[i].bit_fixP;
  1025.       switch (type) {
  1026.       case 1:                /* the object is pure binary */
  1027.         if (j || iif.iifP[i].pcrel) {
  1028.           fix_new_ns32k(frag_now,
  1029.                 (long)(memP-frag_now->fr_literal),
  1030.                 size,
  1031.                 0,
  1032.                 0,
  1033.                 iif.iifP[i].object,
  1034.                 iif.iifP[i].pcrel,
  1035.                 (char)size_so_far, /*iif.iifP[i].pcrel_adjust,*/
  1036.                 iif.iifP[i].im_disp,
  1037.                 j,
  1038.                 iif.iifP[i].bsr); /* sequent hack */
  1039.         } else {            /* good, just put them bytes out */
  1040.           switch (iif.iifP[i].im_disp) {
  1041.           case 0:
  1042.         md_number_to_chars(memP,iif.iifP[i].object,size);break;
  1043.           case 1:
  1044.         md_number_to_disp(memP,iif.iifP[i].object,size);break;
  1045.           default: as_fatal("iif convert internal pcrel/binary");
  1046.           }
  1047.         }
  1048.         memP+=size;
  1049.         rem_size-=size;
  1050.         break;
  1051.       case 2:    /* the object is a pointer at an expression, so unpack
  1052.                  it, note that bignums may result from the expression
  1053.              */
  1054.         if ((segment=evaluate_expr(&exprP,(char*)iif.iifP[i].object))==SEG_BIG || size==8) {
  1055.           if ((k=exprP.X_add_number)>0) { /* we have a bignum ie a quad */
  1056.         /* this can only happens in a long suffixed instruction */
  1057.         bzero(memP,size); /* size normally is 8 */
  1058.         if (k*2>size) as_warn("Bignum too big for long");
  1059.         if (k==3) memP+=2;
  1060.         for (l=0;k>0;k--,l+=2) {
  1061.           md_number_to_chars(memP+l,generic_bignum[l>>1],sizeof(LITTLENUM_TYPE));
  1062.         }
  1063.           } else { /* flonum */
  1064.         switch(size) {
  1065.         case 4:
  1066.           gen_to_words(memP,2,8);
  1067.           break;
  1068.         case 8:
  1069.           gen_to_words(memP,4,11);
  1070.           break;
  1071.         }
  1072.           }
  1073.         memP+=size;
  1074.         rem_size-=size;
  1075.         break;
  1076.         }
  1077.         if (j ||
  1078.         exprP.X_add_symbol ||
  1079.         exprP.X_subtract_symbol ||
  1080.         iif.iifP[i].pcrel) {        /* fixit */
  1081.           /* the expression was undefined due to an undefined label */
  1082.           /* create a fix so we can fix the object later */
  1083.           exprP.X_add_number+=iif.iifP[i].object_adjust;
  1084.           fix_new_ns32k(frag_now,
  1085.                 (long)(memP-frag_now->fr_literal),
  1086.                 size,
  1087.                 exprP.X_add_symbol,
  1088.                 exprP.X_subtract_symbol,
  1089.                 exprP.X_add_number,
  1090.                 iif.iifP[i].pcrel,
  1091.                 (char)size_so_far, /*iif.iifP[i].pcrel_adjust,*/
  1092.                 iif.iifP[i].im_disp,
  1093.                 j,
  1094.                 iif.iifP[i].bsr); /* sequent hack */
  1095.           
  1096.         } else {            /* good, just put them bytes out */
  1097.           switch (iif.iifP[i].im_disp) {
  1098.           case 0:
  1099.         md_number_to_imm(memP,exprP.X_add_number,size);break;
  1100.           case 1:
  1101.         md_number_to_disp(memP,exprP.X_add_number,size);break;
  1102.           default: as_fatal("iif convert internal pcrel/pointer");
  1103.           }
  1104.         }
  1105.         memP+=size;
  1106.         rem_size-=size;
  1107.         break;
  1108.       default: as_fatal("Internal logic error in iif.iifP[n].type");
  1109.       }
  1110.       break;
  1111.     case 0:      /* To bad, the object may be undefined as far as its final
  1112.                 nsize in object memory is concerned. The size of the object
  1113.                 in objectmemory is not explicitly given.
  1114.                 If the object is defined its length can be determined and
  1115.                 a fix can replace the frag.
  1116.                 */
  1117.       {
  1118.         int temp;
  1119.         segment=evaluate_expr(&exprP,(char*)iif.iifP[i].object);
  1120.         if ((exprP.X_add_symbol || exprP.X_subtract_symbol) &&
  1121.         !iif.iifP[i].pcrel) { /* OVE: hack, clamp to 4 bytes */
  1122.           size=4; /* we dont wan't to frag this, use 4 so it reaches */
  1123.           fix_new_ns32k(frag_now,
  1124.                 (long)(memP-frag_now->fr_literal),
  1125.                 size,
  1126.                 exprP.X_add_symbol,
  1127.                 exprP.X_subtract_symbol,
  1128.                 exprP.X_add_number,
  1129.                 0, /* never iif.iifP[i].pcrel, */
  1130.                 (char)size_so_far, /*iif.iifP[i].pcrel_adjust,*/
  1131.                 1, /* always iif.iifP[i].im_disp, */
  1132.                 0,0);
  1133.           memP+=size;
  1134.           rem_size-=4;
  1135.           break; /* exit this absolute hack */
  1136.         }
  1137.  
  1138.         if (exprP.X_add_symbol || exprP.X_subtract_symbol) { /* frag it */
  1139.           if (exprP.X_subtract_symbol) { /* We cant relax this case */
  1140.         as_fatal("Can't relax difference");
  1141.           }
  1142.           else {
  1143.         /* at this stage we must undo some of the effect caused
  1144.            by frag_more, ie we must make sure that frag_var causes
  1145.            frag_new to creat a valid fix-size in the frag it`s closing
  1146.            */
  1147.         temp = -(rem_size-4);
  1148.         obstack_blank_fast(&frags,temp);
  1149.           /* we rewind none, some or all of the requested size we
  1150.              requested by the first frag_more for this iif chunk.
  1151.              Note: that we allocate 4 bytes to an object we NOT YET 
  1152.              know the size of, thus rem_size-4.
  1153.              */
  1154.         (void)frag_variant(rs_machine_dependent,
  1155.                    4,
  1156.                    0,
  1157.                    IND(BRANCH,UNDEF), /* expecting the worst */
  1158.                    exprP.X_add_symbol,
  1159.                    exprP.X_add_number,
  1160.                    (char*)inst_opcode,
  1161.                    (char)size_so_far, /*iif.iifP[i].pcrel_adjust);*/
  1162.                            iif.iifP[i].bsr); /* sequent linker hack */
  1163.         rem_size-=4;
  1164.         if (rem_size>0) {
  1165.           memP=frag_more(rem_size);
  1166.         }
  1167.           }
  1168.         }
  1169.         else {/* Double work, this is done in md_number_to_disp */
  1170.           exprP.X_add_number;
  1171.           if (-64<=exprP.X_add_number && exprP.X_add_number<=63) {
  1172.         size=1;
  1173.           } else {
  1174.         if (-8192<=exprP.X_add_number && exprP.X_add_number<=8191) {
  1175.           size=2;
  1176.         } else {
  1177.           if (-0x1f000000<=exprP.X_add_number &&
  1178.               exprP.X_add_number<=0x1fffffff)
  1179.           /* if (-0x40000000<=exprP.X_add_number &&
  1180.               exprP.X_add_number<=0x3fffffff) */
  1181.           {
  1182.             size=4;
  1183.           } else {
  1184.             as_warn("Displacement to large for :d");
  1185.             size=4;
  1186.           }
  1187.         }
  1188.           }
  1189.           /* rewind the bytes not used */
  1190.           temp = -(4-size);
  1191.           md_number_to_disp(memP,exprP.X_add_number,size);
  1192.           obstack_blank_fast(&frags,temp);
  1193.           memP+=size;
  1194.           rem_size-=4; /* we allocated this amount */
  1195.         }
  1196.       }
  1197.       break;
  1198.     default:
  1199.       as_fatal("Internal logic error in iif.iifP[].type");
  1200.     }
  1201.     size_so_far+=size;
  1202.     size=0;
  1203.       }
  1204.     }
  1205. }
  1206.  
  1207. void md_assemble(line)
  1208. char *line;
  1209. {
  1210.   freeptr=freeptr_static;
  1211.   parse(line,0); /* explode line to more fix form in iif */
  1212.   convert_iif(); /* convert iif to frags, fix's etc */
  1213. #ifdef SHOW_NUM
  1214.   printf(" \t\t\t%s\n",line);
  1215. #endif
  1216. }
  1217.  
  1218.  
  1219. void md_begin()
  1220. {
  1221.   /* build a hashtable of the instructions */
  1222.   register struct ns32k_opcode *ptr;
  1223.   register char *stat;
  1224.   inst_hash_handle=hash_new();
  1225.   for (ptr=ns32k_opcodes;ptr<endop;ptr++) {
  1226.     if (*(stat=hash_insert(inst_hash_handle,ptr->name,(char*)ptr))) {
  1227.     as_fatal("Can't hash %s: %s",ptr->name,stat); /*fatal*/
  1228.       exit(0);
  1229.     }
  1230.   }
  1231.   freeptr_static=(char*)malloc(PRIVATE_SIZE); /* some private space please! */
  1232. }
  1233.  
  1234.  
  1235. void
  1236. md_end()
  1237. {
  1238.   free(freeptr_static);
  1239. }
  1240.  
  1241. #define MAX_LITTLENUMS 4
  1242.  
  1243. /* Turn the string pointed to by litP into a floating point constant of type
  1244.    type, and emit the appropriate bytes.  The number of LITTLENUMS emitted
  1245.    is stored in *sizeP .  An error message is returned, or NULL on OK.
  1246.  */
  1247. char *
  1248. md_atof(type,litP,sizeP)
  1249. char type;
  1250. char *litP;
  1251. int *sizeP;
  1252. {
  1253.     int    prec;
  1254.     LITTLENUM_TYPE words[MAX_LITTLENUMS];
  1255.     LITTLENUM_TYPE *wordP;
  1256.     char    *t;
  1257.     char    *atof_ns32k();
  1258.  
  1259.     switch(type) {
  1260.     case 'f':
  1261.         prec = 2;
  1262.         break;
  1263.  
  1264.     case 'd':
  1265.         prec = 4;
  1266.         break;
  1267.     default:
  1268.         *sizeP=0;
  1269.         return "Bad call to MD_ATOF()";
  1270.     }
  1271.     t=atof_ns32k(input_line_pointer,type,words);
  1272.     if(t)
  1273.         input_line_pointer=t;
  1274.  
  1275.     *sizeP=prec * sizeof(LITTLENUM_TYPE);
  1276.     for(wordP=words;prec--;) {
  1277.         md_number_to_chars(litP,(long)(*wordP++),sizeof(LITTLENUM_TYPE));
  1278.         litP+=sizeof(LITTLENUM_TYPE);
  1279.     }
  1280.     return "";    /* Someone should teach Dean about null pointers */
  1281. }
  1282.  
  1283. /* Convert number to chars in correct order */
  1284.  
  1285. void
  1286. md_number_to_chars (buf, value, nbytes)
  1287.      char    *buf;
  1288.      long int    value;
  1289.      int    nbytes;
  1290. {
  1291.   while (nbytes--)
  1292.     {
  1293. #ifdef SHOW_NUM
  1294.       printf("%x ",value & 0xff);
  1295. #endif
  1296.       *buf++ = value;        /* Lint wants & MASK_CHAR. */
  1297.       value >>= BITS_PER_CHAR;
  1298.     }
  1299. }
  1300. /* Convert number to chars in correct order */
  1301.  
  1302.  
  1303.  
  1304. /* This is a variant of md_numbers_to_chars. The reason for its' existence
  1305.    is the fact that ns32k uses Huffman coded displacements. This implies
  1306.    that the bit order is reversed in displacements and that they are prefixed
  1307.    with a size-tag.
  1308.  
  1309.    binary: msb -> lsb    0xxxxxxx                byte
  1310.                10xxxxxx xxxxxxxx            word
  1311.                11xxxxxx xxxxxxxx xxxxxxxx xxxxxxxx    double word
  1312.           
  1313.    This must be taken care of and we do it here!           
  1314.  */
  1315. void md_number_to_disp(buf,val,n)
  1316.      char    *buf;
  1317.      long    val;
  1318.      char       n;
  1319.   switch(n) {
  1320.   case 1:
  1321.     if (val < -64 || val > 63)
  1322.       as_warn("Byte displacement out of range.  line number not valid");
  1323.     val&=0x7f;
  1324. #ifdef SHOW_NUM
  1325.         printf("%x ",val & 0xff);
  1326. #endif
  1327.     *buf++=val;
  1328.     break;
  1329.   case 2:
  1330.     if (val < -8192 || val > 8191)
  1331.       as_warn("Word displacement out of range.  line number not valid");
  1332.     val&=0x3fff;
  1333.     val|=0x8000;
  1334. #ifdef SHOW_NUM
  1335.         printf("%x ",val>>8 & 0xff);
  1336. #endif
  1337.     *buf++=(val>>8);
  1338. #ifdef SHOW_NUM
  1339.         printf("%x ",val & 0xff);
  1340. #endif
  1341.     *buf++=val;
  1342.     break;
  1343.   case 4:
  1344.     if (val < -0x1f000000 || val >= 0x20000000)
  1345.     /* if (val < -0x20000000 || val >= 0x20000000) */
  1346.       as_warn("Double word displacement out of range");
  1347.     val|=0xc0000000;
  1348. #ifdef SHOW_NUM
  1349.         printf("%x ",val>>24 & 0xff);
  1350. #endif
  1351.     *buf++=(val>>24);
  1352. #ifdef SHOW_NUM
  1353.         printf("%x ",val>>16 & 0xff);
  1354. #endif
  1355.     *buf++=(val>>16);
  1356. #ifdef SHOW_NUM
  1357.         printf("%x ",val>>8 & 0xff);
  1358. #endif
  1359.     *buf++=(val>>8);
  1360. #ifdef SHOW_NUM
  1361.         printf("%x ",val & 0xff);
  1362. #endif
  1363.     *buf++=val;
  1364.     break;
  1365.   default:
  1366.     as_fatal("Internal logic error");
  1367.   }
  1368. }
  1369. void md_number_to_imm(buf,val,n)
  1370.      char    *buf;
  1371.      long    val;
  1372.      char       n;
  1373.   switch(n) {
  1374.   case 1:
  1375. #ifdef SHOW_NUM
  1376.     printf("%x ",val & 0xff);
  1377. #endif
  1378.     *buf++=val;
  1379.     break;
  1380.   case 2:
  1381. #ifdef SHOW_NUM
  1382.         printf("%x ",val>>8 & 0xff);
  1383. #endif
  1384.     *buf++=(val>>8);
  1385. #ifdef SHOW_NUM
  1386.         printf("%x ",val & 0xff);
  1387. #endif
  1388.     *buf++=val;
  1389.     break;
  1390.   case 4:
  1391. #ifdef SHOW_NUM
  1392.         printf("%x ",val>>24 & 0xff);
  1393. #endif
  1394.     *buf++=(val>>24);
  1395. #ifdef SHOW_NUM
  1396.         printf("%x ",val>>16 & 0xff);
  1397. #endif
  1398.     *buf++=(val>>16);
  1399. #ifdef SHOW_NUM
  1400.         printf("%x ",val>>8 & 0xff);
  1401. #endif
  1402.     *buf++=(val>>8);
  1403. #ifdef SHOW_NUM
  1404.         printf("%x ",val & 0xff);
  1405. #endif
  1406.     *buf++=val;
  1407.     break;
  1408.   default:
  1409.     as_fatal("Internal logic error");
  1410.   }
  1411. }
  1412. /* the bit-field entries in the relocation_info struct plays hell 
  1413.    with the byte-order problems of cross-assembly.  So as a hack,
  1414.    I added this mach. dependent ri twiddler.  Ugly, but it gets
  1415.    you there. -KWK */
  1416. /* OVE: on a ns32k the twiddling continues at an even deeper level
  1417.    here we have to distinguish between displacements and immediates.
  1418.  
  1419.    The sequent has a bit for this. It also has a bit for relocobjects that
  1420.    points at the target for a bsr (BranchSubRoutine) !?!?!?!
  1421.  
  1422.    Using [] is importable but fast!! still, its rather funny :-)
  1423.    This md_ri.... is tailored for sequent.
  1424.    */
  1425.  
  1426. void md_ri_to_chars(ri_p, ri)
  1427.      struct relocation_info *ri_p, ri;
  1428. {    
  1429.   if (ri.r_bsr) {ri.r_pcrel=0;} /* sequent seems to want this */
  1430.   md_number_to_chars((char*)ri_p, ri.r_address, sizeof(ri.r_address));
  1431.   md_number_to_chars((char*)ri_p+4,
  1432.              (long)(ri.r_symbolnum       ) |
  1433.              (long)(ri.r_pcrel     << 24 ) |
  1434.              (long)(ri.r_length       << 25 ) |
  1435.              (long)(ri.r_extern       << 27 ) |
  1436.              (long)(ri.r_bsr       << 28 ) |
  1437.              (long)(ri.r_disp       << 29 ),
  1438.              4);
  1439.   /* the first and second md_number_to_chars never overlaps (32bit cpu case) */
  1440. }
  1441.  
  1442. /* fast bitfiddling support */
  1443. /* mask used to zero bitfield before oring in the true field */
  1444.  
  1445. static unsigned long l_mask[]={    0xffffffff, 0xfffffffe, 0xfffffffc, 0xfffffff8,
  1446.                 0xfffffff0, 0xffffffe0, 0xffffffc0, 0xffffff80,
  1447.                 0xffffff00, 0xfffffe00, 0xfffffc00, 0xfffff800,
  1448.                 0xfffff000, 0xffffe000, 0xffffc000, 0xffff8000,
  1449.                 0xffff0000, 0xfffe0000, 0xfffc0000, 0xfff80000,
  1450.                 0xfff00000, 0xffe00000, 0xffc00000, 0xff800000,
  1451.                 0xff000000, 0xfe000000, 0xfc000000, 0xf8000000,
  1452.                 0xf0000000, 0xe0000000, 0xc0000000, 0x80000000,
  1453.                 };
  1454. static unsigned long r_mask[]={    0x00000000, 0x00000001, 0x00000003, 0x00000007,
  1455.                 0x0000000f, 0x0000001f, 0x0000003f, 0x0000007f,
  1456.                 0x000000ff, 0x000001ff, 0x000003ff, 0x000007ff,
  1457.                 0x00000fff, 0x00001fff, 0x00003fff, 0x00007fff,
  1458.                 0x0000ffff, 0x0001ffff, 0x0003ffff, 0x0007ffff,
  1459.                 0x000fffff, 0x001fffff, 0x003fffff, 0x007fffff,
  1460.                 0x00ffffff, 0x01ffffff, 0x03ffffff, 0x07ffffff,
  1461.                 0x0fffffff, 0x1fffffff, 0x3fffffff, 0x7fffffff,
  1462.                 };
  1463. #define MASK_BITS 31
  1464. /* Insert bitfield described by field_ptr and val at buf
  1465.    This routine is written for modification of the first 4 bytes pointed
  1466.    to by buf, to yield speed.
  1467.    The ifdef stuff is for selection between a ns32k-dependent routine
  1468.    and a general version. (My advice: use the general version!)
  1469.  */
  1470.  
  1471. void md_number_to_field(buf,val,field_ptr)
  1472.      register char    *buf;
  1473.      register long    val;
  1474.      register bit_fixS  *field_ptr;
  1475.   register unsigned long object;
  1476.   register unsigned long mask;
  1477. /* define ENDIAN on a ns32k machine */
  1478. #ifdef ENDIAN
  1479.   register unsigned long *mem_ptr;
  1480. #else
  1481.   register char *mem_ptr;
  1482. #endif
  1483.   if (field_ptr->fx_bit_min<=val && val<=field_ptr->fx_bit_max) {
  1484. #ifdef ENDIAN
  1485.     if (field_ptr->fx_bit_base) { /* override buf */
  1486.       mem_ptr=(unsigned long*)field_ptr->fx_bit_base;
  1487.     } else {
  1488.       mem_ptr=(unsigned long*)buf;
  1489.     }
  1490. #else
  1491.     if (field_ptr->fx_bit_base) { /* override buf */
  1492.       mem_ptr=(char*)field_ptr->fx_bit_base;
  1493.     } else {
  1494.       mem_ptr=buf;
  1495.     }
  1496. #endif
  1497.     mem_ptr+=field_ptr->fx_bit_base_adj;
  1498. #ifdef ENDIAN  /* we have a nice ns32k machine with lowbyte at low-physical mem */
  1499.     object = *mem_ptr; /* get some bytes */
  1500. #else /* OVE Goof! the machine is a m68k or dito */
  1501.       /* That takes more byte fiddling */
  1502.     object=0;
  1503.     object|=mem_ptr[3] & 0xff;
  1504.     object<<=8;
  1505.     object|=mem_ptr[2] & 0xff;
  1506.     object<<=8;
  1507.     object|=mem_ptr[1] & 0xff;
  1508.     object<<=8;
  1509.     object|=mem_ptr[0] & 0xff;
  1510. #endif
  1511.     mask=0;
  1512.     mask|=(r_mask[field_ptr->fx_bit_offset]);
  1513.     mask|=(l_mask[field_ptr->fx_bit_offset+field_ptr->fx_bit_size]);
  1514.     object&=mask;
  1515.     val+=field_ptr->fx_bit_add;
  1516.     object|=((val<<field_ptr->fx_bit_offset) & (mask ^ 0xffffffff));
  1517. #ifdef ENDIAN
  1518.     *mem_ptr=object;
  1519. #else
  1520.     mem_ptr[0]=(char)object;
  1521.     object>>=8;
  1522.     mem_ptr[1]=(char)object;
  1523.     object>>=8;
  1524.     mem_ptr[2]=(char)object;
  1525.     object>>=8;
  1526.     mem_ptr[3]=(char)object;
  1527. #endif
  1528.   } else {
  1529.     as_warn("Bit field out of range");
  1530.   }
  1531. }
  1532.  
  1533. /* Convert a relaxed displacement to dito in final output */
  1534.  
  1535. void
  1536.   md_convert_frag(fragP)
  1537. register fragS *fragP;
  1538. {
  1539.   long disp;
  1540.   long ext;
  1541.  
  1542.   /* Address in gas core of the place to store the displacement.  */
  1543.   register char *buffer_address = fragP -> fr_fix + fragP -> fr_literal;
  1544.   /* Address in object code of the displacement.  */
  1545.   register int object_address = fragP -> fr_fix + fragP -> fr_address;
  1546.  
  1547.   know(fragP->fr_symbol);
  1548.  
  1549.   /* The displacement of the address, from current location.  */
  1550.   disp = (fragP->fr_symbol->sy_value + fragP->fr_offset) - object_address;
  1551.   disp+= fragP->fr_pcrel_adjust;
  1552.  
  1553.   switch(fragP->fr_subtype) {
  1554.   case IND(BRANCH,BYTE):
  1555.     ext=1;
  1556.     break;
  1557.   case IND(BRANCH,WORD):
  1558.     ext=2;
  1559.     break;
  1560.   case IND(BRANCH,DOUBLE):
  1561.     ext=4;
  1562.     break;
  1563.   }
  1564.   if(ext) {
  1565.     md_number_to_disp(buffer_address,(long)disp,(int)ext);
  1566.     fragP->fr_fix+=ext;
  1567.   }
  1568. }
  1569.  
  1570.  
  1571.  
  1572. /* This function returns the estimated size a variable object will occupy,
  1573.    one can say that we tries to guess the size of the objects before we
  1574.    actually know it */
  1575.    
  1576. md_estimate_size_before_relax(fragP,segtype)
  1577.      register fragS *fragP;
  1578. {
  1579.   int    old_fix;
  1580.   old_fix=fragP->fr_fix;
  1581.   switch(fragP->fr_subtype) {
  1582.   case IND(BRANCH,UNDEF):
  1583.     if((fragP->fr_symbol->sy_type&N_TYPE)==segtype) {
  1584.       /* the symbol has been assigned a value */
  1585.       fragP->fr_subtype=IND(BRANCH,BYTE);
  1586.     } else {
  1587.       /* we don't relax symbols defined in an other segment
  1588.          the thing to do is to assume the object will occupy 4 bytes */
  1589.       fix_new_ns32k(fragP,
  1590.             (int)(fragP->fr_fix),
  1591.             4,
  1592.             fragP->fr_symbol,
  1593.             (symbolS *)0,
  1594.             fragP->fr_offset,
  1595.             1,
  1596.             fragP->fr_pcrel_adjust,
  1597.             1,
  1598.             0,
  1599.             fragP->fr_bsr); /*sequent hack */
  1600.       fragP->fr_fix+=4;
  1601.       /* fragP->fr_opcode[1]=0xff; */
  1602.       frag_wane(fragP);
  1603.       break;
  1604.     }
  1605.   case IND(BRANCH,BYTE):
  1606.     fragP->fr_var+=1;
  1607.     break;
  1608.   default:
  1609.     break;
  1610.   }
  1611.   return fragP->fr_var + fragP->fr_fix - old_fix;
  1612. }
  1613.  
  1614. int md_short_jump_size = 4;
  1615. int md_long_jump_size  = 6;
  1616.  
  1617. void
  1618. md_create_short_jump(ptr,from_addr,to_addr,frag,to_symbol)
  1619. char    *ptr;
  1620. long    from_addr,
  1621.     to_addr;
  1622. fragS    *frag;
  1623. symbolS    *to_symbol;
  1624. {
  1625.     long offset;
  1626.  
  1627.     offset = to_addr - from_addr;
  1628.     offset |= 0x8000;
  1629.     md_number_to_chars(ptr,  (long)0x927F,2);
  1630.     md_number_to_chars(ptr+2,(long)offset,2);
  1631. }
  1632.  
  1633. void
  1634. md_create_long_jump(ptr,from_addr,to_addr,frag,to_symbol)
  1635. char    *ptr;
  1636. long    from_addr,
  1637.     to_addr;
  1638. fragS    *frag;
  1639. symbolS    *to_symbol;
  1640. {
  1641.     long offset;
  1642.  
  1643.     offset= to_addr - from_addr;
  1644.     offset |= 0xC0000000;
  1645.     md_number_to_chars(ptr,  (long)0x927F,2);
  1646.     md_number_to_chars(ptr+2,(long)offset,4);
  1647. }
  1648.  
  1649. /* JF this is a new function to parse machine-dep options */
  1650. int
  1651. md_parse_option(argP,cntP,vecP)
  1652. char **argP;
  1653. int *cntP;
  1654. char ***vecP;
  1655. {
  1656.     switch(**argP) {
  1657.     case 'm':
  1658.       (*argP)++;
  1659.  
  1660.       if(!strcmp(*argP,"32032")) {
  1661.         cpureg = cpureg_032;
  1662.         mmureg = mmureg_032;
  1663.       } else if(!strcmp(*argP, "32532")) {
  1664.         cpureg = cpureg_532;
  1665.         mmureg = mmureg_532;
  1666.       } else
  1667.         as_warn("Unknown -m option ignored");
  1668.  
  1669.       while(**argP)
  1670.         (*argP)++;
  1671.       break;
  1672.  
  1673.     default:
  1674.       return 0;
  1675.     }
  1676.     return 1;
  1677. }
  1678.  
  1679. /*
  1680.  *            bit_fix_new()
  1681.  *
  1682.  * Create a bit_fixS in obstack 'notes'.
  1683.  * This struct is used to profile the normal fix. If the bit_fixP is a
  1684.  * valid pointer (not NULL) the bit_fix data will be used to format the fix.
  1685.  */
  1686. bit_fixS *
  1687. bit_fix_new (size,offset,min,max,add,base_type,base_adj)
  1688.      char    size;        /* Length of bitfield        */
  1689.      char    offset;        /* Bit offset to bitfield    */
  1690.      long    base_type;    /* 0 or 1, if 1 it's exploded to opcode ptr */
  1691.      long    base_adj;
  1692.      long    min;        /* Signextended min for bitfield */
  1693.      long    max;        /* Signextended max for bitfield */
  1694.      long    add;        /* Add mask, used for huffman prefix */
  1695. {
  1696.   register bit_fixS *    bit_fixP;
  1697.  
  1698.   bit_fixP = (bit_fixS *)obstack_alloc(¬es,sizeof(bit_fixS));
  1699.  
  1700.   bit_fixP -> fx_bit_size    = size;
  1701.   bit_fixP -> fx_bit_offset    = offset;
  1702.   bit_fixP -> fx_bit_base    = base_type;
  1703.   bit_fixP -> fx_bit_base_adj    = base_adj;
  1704.   bit_fixP -> fx_bit_max    = max;
  1705.   bit_fixP -> fx_bit_min    = min;
  1706.   bit_fixP -> fx_bit_add    = add;
  1707.  
  1708.   return bit_fixP;
  1709. }
  1710.  
  1711. void
  1712. fix_new_ns32k (frag, where, size, add_symbol, sub_symbol, offset, pcrel,
  1713.      pcrel_adjust, im_disp, bit_fixP, bsr)
  1714.      fragS *    frag;        /* Which frag? */
  1715.      int    where;        /* Where in that frag? */
  1716.      short int    size;        /* 1, 2  or 4 usually. */
  1717.      symbolS *    add_symbol;    /* X_add_symbol. */
  1718.      symbolS *    sub_symbol;    /* X_subtract_symbol. */
  1719.      long int    offset;        /* X_add_number. */
  1720.      int    pcrel;        /* TRUE if PC-relative relocation. */
  1721.      char    pcrel_adjust;    /* not zero if adjustment of pcrel offset is needed */
  1722.      char    im_disp;    /* true if the value to write is a displacement */
  1723.      bit_fixS *bit_fixP;    /* pointer at struct of bit_fix's, ignored if NULL */
  1724.      char    bsr;        /* sequent-linker-hack: 1 when relocobject is a bsr */
  1725.      
  1726. {
  1727.   register fixS *    fixP;
  1728.  
  1729.   fixP = (fixS *)obstack_alloc(¬es,sizeof(fixS));
  1730.   fixP -> fx_frag        = frag;
  1731.   fixP -> fx_where        = where;
  1732.   fixP -> fx_size        = size;
  1733.   fixP -> fx_addsy        = add_symbol;
  1734.   fixP -> fx_subsy        = sub_symbol;
  1735.   fixP -> fx_offset        = offset;
  1736.   fixP -> fx_pcrel        = pcrel;
  1737.   fixP -> fx_pcrel_adjust    = pcrel_adjust;
  1738.   fixP -> fx_im_disp        = im_disp;
  1739.   fixP -> fx_bit_fixP        = bit_fixP;
  1740.   fixP -> fx_bsr        = bsr;
  1741.   fixP -> fx_next        = * seg_fix_rootP;
  1742.  
  1743.   * seg_fix_rootP = fixP;
  1744. }
  1745.